﻿using Caltech.Service.Common;
using CaltechSoft.Service.EntityFW.Context;
using CaltechSoft.Service.EntityFW.Entity;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Web;

namespace Caltech.Migrations
{
    internal sealed class Configuration : DbMigrationsConfiguration<CaltechContext>
    {

        //Add-Migration name
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(CaltechContext context)
        {
            var userManager = new UserManager<User>(new UserStore<User>(new CaltechContext()));

            var user = new User()
            {
                UserName = "username",
                FirstName = "First",
                LastName = "Last",
                Email = "email@email.com",
                PhoneNumber = "0998766024",
                Tel = "0863232414"
            }; 

            context.Users.AddOrUpdate(x => x.UserName, user);

            context.SaveChanges();

            userManager.AddToRole(user.Id, Roles.Salesman.ToString());
        }
    }
}